﻿$(function () {
    window.lang.run();
    $.kish.ContactUs = {};
    $.extend($.kish.ContactUs, {
        initializing: function () {
            $('.sendBtn_fn').click(function () { $.kish.ContactUs.SendMessage() });
        },


        //*********************************************//
        SendMessage: function () {
            var subject = $.trim($(".subjectTxt_fn").val());
            var body = $.trim($(".bodytxt_fn").val());
            var senderEmail = $.trim($(".senderEmail_fn").val());
            if (subject == "") {
                $(".subjectTxt_fn").css("border-color", 'red');
            };
            if (body == "") {
                $(".bodytxt_fn").css("border-color", 'red');
            }
            if (senderEmail == "") {
                $(".senderEmail_fn").css("border-color", 'red');
            }
            if ((subject == "") || (body == "") || (senderEmail == "")) {
                $.kish.message.getErrorMessage(14);
            }
            else {
                var email = {}
                email.subject = subject;
                email.body = body;
                email.senderEmail = senderEmail;

                $.ajax({
                    'type': 'POST',
                    'url': '../Services/ContactUs.svc/SendEmail',
                    'data': JSON.stringify({ emailToSend: email }),
                    'contentType': 'application/json; charset=utf-8',
                    'dataType': 'json',
                    'async': true,
                    'success': function (result) {
                        if (result['d'].IsSucceed == false) {
                            $.kish.message.getErrorMessage(result['d'].Message.Code);
                        }
                        else {
                            $.kish.message.getUserMessage(result['d'].Message.Code);
                            $(".subjectTxt_fn").val('');
                            $(".bodytxt_fn").val('');
                            $(".senderEmail_fn").val('');
                        }
                    },
                    'error': function (error) { }
                });
            }
        }

    });
    $.kish.ContactUs.initializing();
});